package com.xyy.saas.payment.adpater.chinabank.service;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author wangtianqi
 * @date 2020/7/8 13:35
 */
public class ChinaBankAdapterService {

    private ConcurrentHashMap<String, Method> concurrentHashMap = new ConcurrentHashMap();

    public Map<String, String> wxmini(Map<String, String> params, Map<String, String> extra){
        extra.put("openId", params.get("openId"));
        //goodsSubject 商品描述
        extra.put("goodsSubject",params.get("subject"));
        return extra;
    }

    public Map<String, String> alipaymini(Map<String, String> params, Map<String, String> extra){
        extra.put("userId", params.get("buyerId"));
        extra.put("storeId", params.get("buyerId"));
        extra.put("terminalId", params.get("buyerId"));
        //goodsSubject 商品描述
        extra.put("goodsSubject",params.get("subject"));
        return extra;
    }


    private Class chinaBankAdapterServiceClass = Class.forName("com.xyy.saas.payment.adpater.chinabank.service.ChinaBankAdapterService");

    public Map<String, String> invoker(String methodName, Map<String, Object> params, Map<String, Object> extra) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Method method = concurrentHashMap.get(methodName);
        if (method==null){
            method = chinaBankAdapterServiceClass.getMethod(methodName, Map.class, Map.class);
            concurrentHashMap.put(methodName, method);
        }
        return (Map<String, String>) method.invoke(getInstance(), params, extra);
    }
    private ChinaBankAdapterService() throws ClassNotFoundException {};

    public static ChinaBankAdapterService getInstance() {
        return ChinaBankAdapterService.MyChinaBankAdapterService.instance;
    }

    /**
     * 内部类
     */
    private static class MyChinaBankAdapterService{
        private static ChinaBankAdapterService instance;

        static {
            try {
                instance = new ChinaBankAdapterService();
            } catch (ClassNotFoundException e) {
            }
        }
    }



}
